package me.huanmeng.heater.signalling;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONSupport;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.huanmeng.heater.Heater;

/**
 * 2021/9/27<br>
 * Heater<br>
 *
 * @author huanmeng_qwq
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class Signalling extends JSONSupport {
    private int s;
    private int sn;
    private SignallingData<?> d;
    private JSONObject extra;

    public int getType() {
        return s;
    }

    public SignallingData<?> getData() {
        return d;
    }

    @Override
    public String toJSONString() {
        return toString();
    }

    @Override
    public String toString() {
        return new JSONObject(this).toJSONString(Heater.getIndentFactor());
    }

    @Override
    public void parse(JSON value) {
        super.parse(value);
        d = value.getByPath("d", SignallingData.class);
    }
    public void execute(){
        getData().execute();
    }
}
